layui.use(['table','form'], function () {
    var table = layui.table;
    var form = layui.form;
    var cols = [
        [
            {field: 'id', width: 80, title: 'ID', sort: true},
            {field: 'name', title: '小区名称'},
            {field: 'code', title: '小区编码', sort: true},
            {field: 'parentAreaName', title: '所在省份'},
            {field: 'areaName', title: '所属地区'},
            {field: 'address', title: '详细地址'},
            {title: '操作', fixed: 'right', width: 178, align: 'center', toolbar: '#barDemo'}
        ]
    ];
    var url = '/communityInfo/list';

    showTable(url,cols);//展示表格数据
    reloadTable(url);//搜索按钮
    handlingTable("/communityInfo/delete");//添加或修改或删除操作
    //自定义验证规则
    form.verify({

    });
    submitBtn('/communityInfo/update');

    //联动选择
    form.on('select(prov)',function (data) {
        $('select[name="areaCode"]').empty();
        $.getJSON("/cityArea/getArea?pid="+data.value, function(data){
            var optionstring = "";
            $.each(data.data, function(i,item){
                optionstring += "<option value=\"" + item.areaCode + "\" >" + item.areaName + "</option>";
            });
            $('select[name="areaCode"]').html('<option value="">请选择所在市</option>' + optionstring);
            form.render('select'); //这个很重要
        });
    });






});